//
// BaseHTTPRequest.h
//
// $Id: //base/src/rtsp/BaseHTTPRequest.h
//
// Library: base
// Package: rtsp
// Module : RTSPRequest
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the BaseHTTPRequest class.
//
// Copyright (c) 2012-2012, iGuard.
//

#include "BaseHTTPRequest.h"
#include <sstream>

BaseHTTPRequest::BaseHTTPRequest()
{
}

	
BaseHTTPRequest::BaseHTTPRequest(const std::string& version):
	HTTPRequest(version)
{
}

	
BaseHTTPRequest::BaseHTTPRequest(const std::string& method, const std::string& uri):
	HTTPRequest(method,uri)
{
}


BaseHTTPRequest::BaseHTTPRequest(const std::string& method, const std::string& uri, const std::string& version):
				HTTPRequest(method,uri,version)
{
}


BaseHTTPRequest::~BaseHTTPRequest()
{
}
void BaseHTTPRequest::setContentBody(const std::string& body)
{
	_body = body;
}
const std::string& BaseHTTPRequest::getContentBody() const
{
	return _body;
}
void BaseHTTPRequest::write(std::ostream& ostr) const
{
	HTTPRequest::write(ostr);
	if (!_body.empty())
		ostr << _body;// << "\r\n";
}


void BaseHTTPRequest::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();
	HTTPRequest::read(istr);
	int ch = istr.get();
	while (ch != eof) { _body += (char) ch;ch = istr.get(); }
}
void BaseHTTPRequest::setMessage(const std::string& message)
{
	std::istringstream istr(message);
	read(istr);
}
void BaseHTTPRequest::getMessage(std::string& message)
{
	std::ostringstream ostr;
	write(ostr);
	message = ostr.str();
}